#include <bits/stdc++.h>
using namespace std;
int dp[105][105][105],a[105];
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int T;cin>>T;
	while(T--){
		int n;
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		for(int i=0;i<=100;i++)
			for(int j=0;j<=100;j++)
				for(int k=0;k<=100;k++)
					dp[i][j][k]=-1<<30;
		dp[0][0][0]=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<=100;j++){
				for(int k=0;k<=100;k++){
					if(dp[i][j][k]<0) continue;
					dp[i+1][a[i+1]][k]=max(dp[i+1][a[i+1]][k],dp[i][j][k]+a[i+1]*(a[i+1]==j) );
					dp[i+1][j][a[i+1]]=max(dp[i+1][j][a[i+1]],dp[i][j][k]+a[i+1]*(a[i+1]==k) );
				}
			}
		}
		int ans=0;
		for(int i=0;i<=100;i++){
			for(int j=0;j<=100;j++){
				ans=max(ans,dp[n][i][j]);
			}
		}
		cout<<ans<<endl;
	}
}
